def ifprost(s):
    boolean = True
    if len(str(s)) != 3:
        boolean = False
    for d in range(2, int(s ** 0.5) + 1):
        if s % d == 0:
            boolean = False
            break
    return boolean


digits = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}

s = input().split()
if len(s) != 3 or not (set(s) <= set(digits.keys())):
    print("Wrong input")
    exit()

s = digits[s[0]] * 100 + digits[s[1]] * 10 + digits[s[2]]
if ifprost(s):
    print(s)
else:
    prost1 = s
    while not ifprost(prost1):
        prost1 += 1
    prost2 = s
    while not ifprost(prost2):
        prost2 -= 1
    if abs(s - prost1) >= abs(s - prost2):
        print(prost2)
    else:
        print(prost1)
